
const port = 8066;

const url = require('url');

const http = require('http');

let start = (route)=> {

	let onRequest = (req,res) => {
		
		let pathName = url.parse(req.url).pathname;

		let param = url.parse(req.url).query;

		pathName = pathName.replace(/\//,'');

		if(pathName=== 'favicon.ico') return;

		route(pathName,req,res);

		console.log('url模块与http模块处理url，结果是pathname：'+pathName);

		res.writeHead('200',{"content-type":'text/plain;charset=utf-8'});

		res.write('hello,输入路径是：'+ pathName+param);

		res.end();

	}

	let onStartSuccess = ()=> {

		console.log('http 模块创建服务成功的回调');
	}

	http.createServer(onRequest).listen(port,onStartSuccess);

	console.log("Server has started.");

}


exports.start = start;
